package search

type pawnInfo struct {
	hash zobristHash
	/*	open files: 1-8 (0-256)
	 */
	info int64
}

func (this *pawnInfo) Hash() zobristHash {
	return this.hash
}

const bitMaskOpenFiles = 0xFF

func (this *pawnInfo) OpenFiles() int32 {
	return int32(this.info & bitMaskOpenFiles)
}

// because x % 2^n == x & (2^n - 1), which is faster
const pawnHashTableSize = 1 << 15

type PawnHashTable struct {
	rows [pawnHashTableSize]pawnInfo
}

func (this *PawnHashTable) save(hash zobristHash, openFiles int32) {

	pawnInfo := &this.rows[hash&(pawnHashTableSize-1)]
	pawnInfo.hash = hash
	pawnInfo.info = int64(openFiles)
}

func (this *PawnHashTable) get(hash zobristHash) *pawnInfo {

	pawnInfo := &this.rows[hash&(pawnHashTableSize-1)]
	if pawnInfo.Hash() != hash {
		return nil
	}
	return pawnInfo
}

// for tests
func (this *PawnHashTable) clear() {

	for i := range this.rows {
		this.rows[i].hash = 0
	}
}
